<html>
<head>
<meta charset="UTF-8" />
<script>
	//去重函数
	/* function removeDuplicate(arr){
		var n = []; //一个新的临时数组
		for(var i = 0; i < arr.length; i++){ //遍历当前数组
			console.log(arr[i]+"\t"+n+"\t"+n.indexOf(arr[i]));
			if (n.indexOf(arr[i]) == -1){
				n.push(arr[i]);
			}
		}
		return n;
	}
	var arr = ["aaaa","aaa","aa","aa",1,1];
	var arr2 = removeDuplicate(arr);
	console.log(arr2);  */

	//去重3
	Array.prototype.unique3 = function() {
		var res = [];
		var json = {};
		for (var i = 0; i < this.length; i++) {
			console.log(json[this[i]]);
			if (!json[this[i]]) {
				res.push(this[i]);
				json[this[i]] = 1;
			}
		}
		return res;
	}
	var arr = [ 112, 112, 34, '你好', 112, 112, 34, '你好', 'str', 'str1' ];
	console.log(arr.unique3());

	//字符串反转
	/* function strReverse(str) {
	    var arr = str.split('');
	    var arrReverse = arr.reverse();
	    var result = "";
	    for(var i=0; i<arrReverse.length;i++){
	    	result+=arrReverse[i];
	    }
	    return result;
	}
	var str = "123456";
	console.log(strReverse(str)); //输出结果是6,5,4,3,2,1
	console.log(typeof strReverse(str)); //输出结果是string */

	//闭包题目1
	/* function fn(a) {
	    return function(b) {
	        return a + b;
	    }
	}
	var x = fn(5);//x:a=5
	var x = fn(4);//x:a=4
	var z = fn(7);//z:a=7
	
	console.log(x(1));//4+1=5
	console.log(x(3));//4+3=7
	console.log(y(1));//7+1=8 */

	//js递归
	/* function fact(num) {
	    if (num <= 1) {
	        return 1;
	    } else {
	        return num * fact(num - 1);
	    }
	}
	var a = fact(4);
	
	console.log(a); */

	//字符长度1
	/* function countStrLength(str){
		 return str.replace(/[^\x00-\xff]/g, 'xx').length;//包含
	}
	//字符长度2
	function countStrLength2(str){
		var result = 0;
		for(var i = 0; i<str.length; i++){
			if(str.charCodeAt(i)>255){
				result+=2;
			}else{
				result++;
			}
		}
		return result;
	}
	console.log(countStrLength("a中文"));
	console.log(countStrLength2("a中文")); */

	//判断对象类型
	/* var a = "";
	var d = new Date(a);
	console.log(a.constructor == String ); */
</script>


</head>
<body>

</body>
</html>